/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.icatportal.client.mvc;


import com.extjs.gxt.ui.client.mvc.AppEvent;
import com.extjs.gxt.ui.client.mvc.Controller;
import com.extjs.gxt.ui.client.mvc.Dispatcher;
import org.icatportal.client.AppEvents;

/**
 *
 * @author ll56
 */
public class AppController extends Controller {

    private AppView appView;

  public AppController() {
    registerEventTypes(AppEvents.Init);
    registerEventTypes(AppEvents.Login);
    registerEventTypes(AppEvents.Error);
  }
    @Override
    public void handleEvent(AppEvent event) {
        switch (event.type) {
            case AppEvents.Init:
                onInit(event);
                break;
            case AppEvents.Login:
                onLogin(event);
                break;
            case AppEvents.Error:
                onError(event);
                break;
        }
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void initialize() {
        appView = new AppView(this);
    }

    private void onError(AppEvent event) {
        throw new UnsupportedOperationException("Not yet implemented");
    }

    private void onInit(AppEvent event) {
        forwardToView(appView, event);
        Dispatcher.forwardEvent(AppEvents.Search);


        throw new UnsupportedOperationException("Not yet implemented");
    }

    private void onLogin(AppEvent event) {
        forwardToView(appView, event);
    }

}
